
//
//  FZHomeStatusToolBarView.swift
//  FZSina_Swift
//
//  Created by 李忠 on 7/24/16.
//  Copyright © 2016 FZLZ. All rights reserved.
//

import UIKit

class FZHomeStatusToolBarView: UIView {
    
    var status: FZHomeStatusViewModel?{
        didSet{
            let reposts_count = status?.status?.reposts_count ?? 0
            let comments_count = status?.status?.comments_count ?? 0
            let attitudes_count = status?.status?.attitudes_count ?? 0
            
            if  reposts_count != 0{
                retweetButton.setTitle("\(reposts_count)", forState: UIControlState.Normal)
            }else{
                retweetButton.setTitle("转发", forState: UIControlState.Normal)
            }
            
            if  comments_count != 0 {
                commentButton.setTitle("\(comments_count)", forState: UIControlState.Normal)
            }else{
                commentButton.setTitle("评论", forState: UIControlState.Normal)
            }
            if  attitudes_count != 0 {
                unlikeButton.setTitle("\(attitudes_count)", forState: UIControlState.Normal)
            }else{
                unlikeButton.setTitle("赞", forState: UIControlState.Normal)
            }
            
            
        }
    }

    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
        setupLayout()        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
//MARK:==========================加载界面==========================
    
    func setupUI() {
        self.backgroundColor = UIColor.whiteColor()
        addSubview(separatorView)
        addSubview(retweetButton)
        addSubview(commentButton)
        addSubview(unlikeButton)
        addSubview(leftIMGView)
        addSubview(rightIMGView)
    }
    func setupLayout() {
        
        separatorView.snp_makeConstraints { (make) in
            make.top.leading.trailing.equalTo(0)
            make.height.equalTo(1)
        }
        
        retweetButton.snp_makeConstraints { (make) in
            make.top.bottom.leading.equalTo(0)
            make.size.equalTo(commentButton)
            
        }
        
        leftIMGView.snp_makeConstraints { (make) in
            make.centerX.equalTo(retweetButton.snp_trailing)
            make.centerY.equalTo(self)
        }
        commentButton.snp_makeConstraints { (make) in
            make.top.equalTo(retweetButton)
            make.leading.equalTo(retweetButton.snp_trailing)
            
            make.trailing.equalTo(unlikeButton.snp_leading)
            make.size.equalTo(retweetButton)
        }
        rightIMGView.snp_makeConstraints { (make) in
            make.centerX.equalTo(commentButton.snp_trailing)
            make.centerY.equalTo(self)
        }
        unlikeButton.snp_makeConstraints { (make) in
            make.top.equalTo(retweetButton)
            make.trailing.equalTo(0)
            make.size.equalTo(retweetButton)
        }
    }

//MARK:==========================事件==========================
    
    @objc private func retweetClickButton() {
        print("retweetClickButton")
    }
    @objc private func commentClickButton() {
        print("commentClickButton")
    }
    @objc private func unlikeClickButton() {
        print("unlikeClickButton")
    }

//MARK:==========================懒加载==========================
    private lazy var retweetButton: UIButton = UIButton(target: self, action:  #selector(retweetClickButton), title: "转发", titleColor: UIColor.grayColor(), imageNamed: "timeline_icon_retweet")
    
    private lazy var commentButton: UIButton = UIButton(target: self, action:  #selector(commentClickButton), title: "评论", titleColor: UIColor.grayColor(), imageNamed: "timeline_icon_comment")
    
    private lazy var unlikeButton: UIButton = UIButton(target: self, action:  #selector(unlikeClickButton), title: "赞", titleColor: UIColor.grayColor(), imageNamed: "timeline_icon_unlike")
    
    private lazy var leftIMGView = UIImageView(imgNamed: "timeline_card_bottom_line")
    private lazy var rightIMGView = UIImageView(imgNamed: "timeline_card_bottom_line")
    private lazy var separatorView: UIView = {
       let iv = UIView()
        iv.backgroundColor = TheTableColor
        return iv
    }()
}
